var isMobile = require('ismobilejs');

function matchTheme(req, res) {
    res.locals.theme = isMobile(req.headers['user-agent']).any ? "mobile" : "default";
}
module.exports = {
    index: function(req, res, next) {
        matchTheme(req, res);
        var category = req.param("id");
        if (!category) {
            return res.notFound();
        }
        res.locals.currentMenu = category;
        res.locals.theme = "default";
        res.locals.view = category;
        Category.findOne({
            dir: category
        }).then(category => {
            res.locals.category = category;
        }).then(() => Category.find({
            isnavigation: 1
        })).then(function(root_categorys) {
            res.locals.root_categorys = root_categorys;
            return res.templet({});
        }).catch(next);

        // return res.templet({});
    }
};